package org.example.demo1;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet("/RegTest")
public class RegTest extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
        //编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        // 获取表单数据
        String uname = request.getParameter("uname");
        String pwd = request.getParameter("pwd");
        String sex = request.getParameter("sex");
        String[] hobbies = request.getParameterValues("hobby");
        String city = request.getParameter("city");
        String info = request.getParameter("info");

        // 处理数据（这里只是简单地打印）

        System.out.println("用户名: " + uname);
        System.out.println("密码: " + pwd);
        System.out.println("性别: " + sex);
        System.out.println("爱好: " + (hobbies != null ? String.join(", ", hobbies) : ""));
        System.out.println("城市: " + city);
        System.out.println("个人简介: " + info);

//        // 重定向到结果页面
//        response.sendRedirect("result.jsp");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>注册成功！</h1>");
        out.println("<p>感谢您的注册。</p>");
        out.println("</body></html>");
    }
}